package com.example.jegotrip.fragment.shop;

import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

import com.example.jegotrip.R;
import com.example.jegotrip.activity.ProductDetailsActivity;
import com.example.jegotrip.adapter.LeftShopListAdapter;
import com.example.jegotrip.adapter.RightShopListAdapter;
import com.example.jegotrip.base.BaseFragment;
import com.example.jegotrip.entity.DataService;
import com.example.jegotrip.entity.ProductInfo;
import com.example.jegotrip.utils.CustomToast;
import com.example.jegotrip.utils.LogUtil;

import java.util.ArrayList;
import java.util.List;

public class ShoppingFragment extends BaseFragment {
    private RecyclerView leftRecyclerView;
    private RecyclerView rightRecyclerView;

    private LeftShopListAdapter leftShopListAdapter;
    private RightShopListAdapter rightShopListAdapter;

    private List<String> leftDataList = new ArrayList<>();
    private List<ProductInfo> rightDataList = new ArrayList<>();

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        leftDataList.add("首页");
        leftDataList.add("饮料");
        leftDataList.add("家电");
        leftDataList.add("电脑");
        leftDataList.add("化妆品");
        leftDataList.add("奢侈品");

        leftShopListAdapter = new LeftShopListAdapter(leftDataList);
        leftRecyclerView.setAdapter(leftShopListAdapter);

//        一级分类点击事件实现
        leftShopListAdapter.setMleftListOnClickItemListener(new LeftShopListAdapter.LeftListOnClickItemListener() {
            @Override
            public void onItemClick(int position) {
                leftShopListAdapter.setCurrentIndex(position);
                rightShopListAdapter.setListData(DataService.getProductsByPosition(position));
            }
        });

        rightDataList = DataService.getProducts();
        rightShopListAdapter = new RightShopListAdapter(rightDataList);
        rightRecyclerView.setAdapter(rightShopListAdapter);
        // 二级商品列表点击事件跳转商品详情页面
        rightShopListAdapter.setmRightListOnClickItemListener(new RightShopListAdapter.RightListOnClickItemListener() {
            @Override
            public void onItemClick(ProductInfo productInfo, int position) {
                Intent intent = new Intent(getActivity(), ProductDetailsActivity.class);
                intent.putExtra("product_info", productInfo);
                LogUtil.d("productInfo:", String.valueOf(intent.getExtras()));
                startActivity(intent);
            }
        });
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void setListener() {

    }

    @Override
    protected void initViews() {
        leftRecyclerView = rootView.findViewById(R.id.left_recycler_view);
        rightRecyclerView = rootView.findViewById(R.id.right_recycler_view);
    }

    @Override
    protected int getLayoutResOId() {
        return R.layout.fragment_shopping;
    }
}
